﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class smallclassedit : System.Web.UI.Page
{

	protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["User"]==null)
		{
			Response.Write("<script language=javascript>alert('您没有管理权限或者还没有登录，请先登录！');window.open('../login.aspx','_top');</script>");
			Response.End();
		}
		if (!Page.IsPostBack)
        {
            string id = Request.QueryString["id"];
            HiddenID.Value = id;
            if (!string.IsNullOrEmpty(id))
            {
                DataSet ds = Socut.Data.ExecuteDataSet("select smallclassname,smallclassorder,bigclassid from web_music_smallclass where id=" + id);
                STRtitle.Text = ds.Tables[0].Rows[0][0].ToString();
                STRorder.Text = ds.Tables[0].Rows[0][1].ToString();
				string bigclassid = ds.Tables[0].Rows[0][2].ToString();
    			smallbind();
				this.DropDownList1.Items.FindByValue(bigclassid).Selected=true;
				
				
            }
			else
			{
    			smallbind();
				
            }
			
        }
    }
	
	private void smallbind()
	{
				DataSet dss = Socut.Data.ExecuteDataSet("select bigclassname,id from web_music_bigclass order by id");
				this.DropDownList1.DataSource=dss.Tables[0].DefaultView; 
				this.DropDownList1.DataTextField="bigclassname"; 
				this.DropDownList1.DataValueField = "id"; 
				this.DropDownList1.DataBind(); 

	}
	
    protected void Button1_Click(object sender, EventArgs e)
    {
        string Msg, Url;
        if (string.IsNullOrEmpty(HiddenID.Value))
        {
            Socut.Data.ExecuteNonQuery("insert into web_music_smallclass (smallclassname,smallclassorder,bigclassid) values ('" + STRtitle.Text + "','" +  STRorder.Text + "','" +  DropDownList1.Text + "')");
            Msg = "添加成功！";
            Url = "smallclassmanage.aspx";
        }
        else
        {
            Socut.Data.ExecuteNonQuery("update web_music_smallclass set smallclassname='" + STRtitle.Text + "',smallclassorder='" +  STRorder.Text + "',bigclassid='" +  DropDownList1.Text + "' where id=" + HiddenID.Value);
            Msg = "修改成功！";
            Url = "smallclassmanage.aspx";
        }
        CommonFunction.ShowMessage(Msg,Url);
    }
}
